/**********************************************************************************************************************
 * Copyright (c) Prophesee S.A.                                                                                       *
 *                                                                                                                    *
 * Licensed under the Apache License, Version 2.0 (the "License");                                                    *
 * you may not use this file except in compliance with the License.                                                   *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0                                 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed   *
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.                      *
 * See the License for the specific language governing permissions and limitations under the License.                 *
 **********************************************************************************************************************/

// ISSD sequences generated by psee_issd_convert.
// Parameters:
// issd_csv_format_version=1.0
// system=evk3_saphir_cd
// operator=Prophesee
// dry_run=False
// no_system=False
// strip_prefix=False
// sensor_version=None
// args=-s evk3_saphir_cd -o Prophesee
// sensor=PseeEvk3Saphir
// date=2023-03-22T17:51:37
// psee_issd_version=1.3.0
// psee_sensor_lib_version=3.5.0.171+ge2fe7fcc2
// issd_data_format_version=1.0

// clang-format off

#include <vector>

namespace Metavision {

static const std::vector<RegisterOperation> issd_genx320es_cx3_init = {
    RegisterOperation::Write(0x0000001C, 0x00000001),
    RegisterOperation::Write(0x00009008, 0x00000320),
    RegisterOperation::Write(0x00009008, 0x00010320),
    RegisterOperation::Write(0x00000200, 0x00000000),
    RegisterOperation::Write(0x00000214, 0x000004A0),
    RegisterOperation::Write(0x00000214, 0x000004A1),
    RegisterOperation::Write(0x00000204, 0x00008E74),
    RegisterOperation::Write(0x0000020C, 0x00000033),
    RegisterOperation::Write(0x00000204, 0x00000E75),
    RegisterOperation::Write(0x00000204, 0x00000E77),
    RegisterOperation::Write(0x00000210, 0x00000C00),
    RegisterOperation::Write(0x0000B00C, 0x00000002),
    // clk_config: in_div: 1, pll_in_freq: 10.0, ndiv: 80, pll_vco_freq: 1600.0, phy_freq=800.0, mipi_freq=800.0, evt_icn_freq=25, cpu_ss_freq=25, esc_freq=12.5
    RegisterOperation::Write(0x00009008, 0x00000190),
    RegisterOperation::Write(0x0000004C, 0x00204E20),
    // PMU MIPI On ...
    RegisterOperation::Write(0x0000001C, 0x00000004),
    RegisterOperation::Write(0x0000A000, 0x00000406),
    RegisterOperation::Write(0x0000A01C, 0x0007641F),
    RegisterOperation::Write(0x0000B030, 0x00000010),
    RegisterOperation::Write(0x0000004C, 0x00204E22),
    RegisterOperation::Delay(100),
    RegisterOperation::Write(0x0000A01C, 0x0007E41F),
    RegisterOperation::Delay(300),
    RegisterOperation::Write(0x0000004C, 0x00204E20),
    // DIGITAL INIT sequence -- begin
    // DIGITAL: MIPI mode
    RegisterOperation::Write(0x0000001C, 0x00000004),
    RegisterOperation::Write(0x0000B00C, 0x00000F02),
    RegisterOperation::Write(0x0000B030, 0x00000013),
    RegisterOperation::Write(0x0000B030, 0x0000001F),
    RegisterOperation::Delay(199),
    RegisterOperation::Write(0x0000B404, 0x00000068),
    RegisterOperation::Write(0x0000B470, 0x0000000D),
    RegisterOperation::Write(0x0000B45C, 0x00000030),
    RegisterOperation::Write(0x0000B4E4, 0x00000000),
    RegisterOperation::Write(0x0000B434, 0x0000000C),
    RegisterOperation::Write(0x0000B4A0, 0x0000000C),
    RegisterOperation::Write(0x0000B010, 0x00000000),
    RegisterOperation::Write(0x0000B000, 0x1000C000),
    RegisterOperation::Write(0x0000704C, 0x00002710),
    RegisterOperation::Write(0x00007100, 0x0000FFFF),
    RegisterOperation::Write(0x000000B8, 0x00000020),
    RegisterOperation::Write(0x000000C0, 0x000000B8),
    RegisterOperation::Write(0x0000B000, 0x1000C001),
    // DIGITAL: EVT mode
    RegisterOperation::Write(0x0000E000, 0x00000005),
    RegisterOperation::Write(0x0000C000, 0x00000005),
    RegisterOperation::Write(0x0000D000, 0x00000005),
    RegisterOperation::Write(0x00006000, 0x00000000),
    RegisterOperation::Write(0x00006000, 0x00000005),
    RegisterOperation::Write(0x000060A0, 0x00000000),
    RegisterOperation::Write(0x00007044, 0x00000002),
    RegisterOperation::Write(0x00007048, 0x00000000),
    RegisterOperation::Write(0x00007000, 0x00000001),
    // DIGITAL: RO config
    RegisterOperation::Write(0x00009008, 0x00000194),
    // DIGITAL: RO enable, wait for Timebase enable
    RegisterOperation::Write(0x00009000, 0x00000200),
    // DIGITAL INIT sequence -- end
    RegisterOperation::Write(0x0000B000, 0x10008801),
    RegisterOperation::Write(0x0000B024, 0x80003E80),
    // ANALOG INIT sequence -- begin
    RegisterOperation::Write(0x0000001C, 0x00000004),
    // HV biases starting...
    RegisterOperation::Write(0x00001218, 0x00000111),
    RegisterOperation::Write(0x00001218, 0x00000111),
    RegisterOperation::Write(0x00001218, 0x00000111),
    RegisterOperation::Delay(200),
    RegisterOperation::Write(0x00001220, 0x00000001),
    RegisterOperation::Delay(200),
    // PMU On ...
    RegisterOperation::Write(0x0000A008, 0x00008085),
    RegisterOperation::Write(0x0000A004, 0x00008025),
    RegisterOperation::Delay(1000),
    RegisterOperation::Write(0x00000070, 0x0000055F),
    RegisterOperation::Delay(1000),
    // LV biases starting...
    RegisterOperation::Write(0x00001220, 0x00000003),
    RegisterOperation::Delay(200),
    // bias resets released
    RegisterOperation::Write(0x00001208, 0x00000030),
    RegisterOperation::Delay(200),
    // Initialize ROI ...
    // Close the ROI latches...
    RegisterOperation::Write(0x00000000, 0x00000420),
    RegisterOperation::Write(0x00000000, 0x00000400),
    // Setting the ROI to manual mode...
    RegisterOperation::Write(0x00000000, 0x00000802),
    RegisterOperation::Write(0x00000000, 0x00000822),
    RegisterOperation::Write(0x00000000, 0x00000802),
    RegisterOperation::Write(0x00003000, 0x00000000),
    RegisterOperation::Write(0x00003004, 0x00000000),
    RegisterOperation::Write(0x00003008, 0x00000000),
    RegisterOperation::Write(0x0000300C, 0x00000000),
    RegisterOperation::Write(0x00003010, 0x00000000),
    RegisterOperation::Write(0x00003014, 0x00000000),
    RegisterOperation::Write(0x00003018, 0x00000000),
    RegisterOperation::Write(0x0000301C, 0x00000000),
    RegisterOperation::Write(0x00003020, 0x00000000),
    RegisterOperation::Write(0x00003024, 0x00000000),
    RegisterOperation::Write(0x00003028, 0x00000000),
    RegisterOperation::Write(0x00000000, 0x00000822),
    RegisterOperation::Write(0x00000000, 0x00000802),
    // Setting the ROI to manual mode...done!
    RegisterOperation::Write(0x00002000, 0x00000000),
    RegisterOperation::Write(0x00002004, 0x00000000),
    RegisterOperation::Write(0x00002008, 0x00000000),
    RegisterOperation::Write(0x0000200C, 0x00000000),
    RegisterOperation::Write(0x00002010, 0x00000000),
    RegisterOperation::Write(0x00002014, 0x00000000),
    RegisterOperation::Write(0x00002018, 0x00000000),
    RegisterOperation::Write(0x0000201C, 0x00000000),
    RegisterOperation::Write(0x00002020, 0x00000000),
    RegisterOperation::Write(0x00002024, 0x00000000),
    RegisterOperation::Write(0x00003000, 0xFFFFFFFF),
    RegisterOperation::Write(0x00003004, 0xFFFFFFFF),
    RegisterOperation::Write(0x00003008, 0xFFFFFFFF),
    RegisterOperation::Write(0x0000300C, 0xFFFFFFFF),
    RegisterOperation::Write(0x00003010, 0xFFFFFFFF),
    RegisterOperation::Write(0x00003014, 0xFFFFFFFF),
    RegisterOperation::Write(0x00003018, 0xFFFFFFFF),
    RegisterOperation::Write(0x0000301C, 0xFFFFFFFF),
    RegisterOperation::Write(0x00003020, 0xFFFFFFFF),
    RegisterOperation::Write(0x00003024, 0xFFFFFFFF),
    RegisterOperation::Write(0x00000000, 0x00000822),
    RegisterOperation::Write(0x00000000, 0x00000802),
    // Close the ROI latches...done!
    RegisterOperation::Delay(1),
    RegisterOperation::Write(0x00001104, 0x01010018),
    RegisterOperation::Write(0x00001128, 0x01010018),
    RegisterOperation::Write(0x0000110C, 0x01010013),
    RegisterOperation::Write(0x00001130, 0x01010013),
    RegisterOperation::Write(0x00001000, 0x0301003D),
    RegisterOperation::Write(0x00001004, 0x0301001D),
    RegisterOperation::Write(0x00001008, 0x0101003F),
    RegisterOperation::Write(0x00001100, 0x03010000),
    RegisterOperation::Write(0x00001104, 0x01010028),
    RegisterOperation::Write(0x00001108, 0x01010033),
    RegisterOperation::Write(0x0000110C, 0x01010028),
    RegisterOperation::Write(0x00001110, 0x01010039),
    RegisterOperation::Write(0x00001114, 0x03010052),
    RegisterOperation::Write(0x00001118, 0x03010042),
    RegisterOperation::Write(0x0000111C, 0x03000074),
    RegisterOperation::Write(0x00001120, 0x010000A4),
    RegisterOperation::Write(0x00001208, 0x00000035),
    // ANALOG INIT sequence -- end
    RegisterOperation::Write(0x00000000, 0x00000802)
};

static const std::vector<RegisterOperation> issd_genx320es_cx3_start = {
    // DIGITAL START sequence -- begin
    // DIGITAL: MIPI enable
    RegisterOperation::Write(0x0000B000, 0x10008801),
    // DIGITAL: RO exit LowPower + timebase enable
    RegisterOperation::Write(0x00009028, 0x00000000),
    RegisterOperation::WriteField(0x00009008, 0x00000195, 0x00000001),
    // DIGITAL START sequence -- end
    // ANALOG START sequence -- begin
    RegisterOperation::Delay(1),
    RegisterOperation::Write(0x0000002C, 0x0022C724),
    RegisterOperation::Write(0x00000000, 0x00000C02),
    RegisterOperation::Delay(1),
    // ANALOG START sequence -- end
};

static const std::vector<RegisterOperation> issd_genx320es_cx3_stop = {
    // ANALOG STOP sequence -- begin
    RegisterOperation::Write(0x00000000, 0x00000802),
    RegisterOperation::Write(0x0000002C, 0x00200624),
    // ANALOG STOP sequence -- end
    // DIGITAL STOP sequence -- begin
    // DIGITAL: Enter Low Power
    RegisterOperation::Write(0x00009028, 0x00000002),
    RegisterOperation::Delay(1000),
    // DIGITAL: Timebase disable
    RegisterOperation::WriteField(0x00009008, 0x00000194, 0x00000001),
    // DIGITAL: MIPI DPHY disable
    RegisterOperation::Write(0x0000B000, 0x10008800),
    // DIGITAL STOP sequence -- end
};

static const std::vector<RegisterOperation> issd_genx320es_cx3_destroy = {
    // ANALOG DESTROY sequence -- begin
    RegisterOperation::Delay(1),
    // Disabling the PMU...
    RegisterOperation::Write(0x00000070, 0x0000055C),
    RegisterOperation::Write(0x0000A004, 0x00000024),
    RegisterOperation::Write(0x0000A008, 0x00000084),
    RegisterOperation::Write(0x0000005C, 0x00000080),
    RegisterOperation::Write(0x0000005C, 0x00000080),
    RegisterOperation::Write(0x0000A01C, 0x0013601C),
    RegisterOperation::Write(0x0000A000, 0x00000400),
    // Disabling the PMU...done!
    RegisterOperation::Delay(1),
    // ANALOG DESTROY sequence -- end
    // DIGITAL DESTROY sequence -- begin
    // DIGITAL: MIPI DPHY and PLL Power Down
    RegisterOperation::Write(0x0000B030, 0x00000013),
    RegisterOperation::Write(0x0000B00C, 0x00000102),
    RegisterOperation::Write(0x0000B030, 0x00000010),
    RegisterOperation::Write(0x0000B00C, 0x00000002),
    RegisterOperation::Write(0x0000A01C, 0x0013601C),
    RegisterOperation::Write(0x0000004C, 0x00204E20),
    RegisterOperation::Write(0x0000B030, 0x00000000),
    RegisterOperation::Write(0x0000A01C, 0x0013601C),
    RegisterOperation::Write(0x0000A000, 0x00000400),
    RegisterOperation::Write(0x00000204, 0x00000E75),
    RegisterOperation::Write(0x00000204, 0x00000E74),
    RegisterOperation::Write(0x00000214, 0x000184A0),
    // DIGITAL DESTROY sequence -- end
};

static Issd issd_genx320es_cx3_sequence = Issd{
    issd_genx320es_cx3_init,
    issd_genx320es_cx3_start,
    issd_genx320es_cx3_stop,
    issd_genx320es_cx3_destroy,
};

} // namespace Metavision

// clang-format on
